package com.superquan.springcloud.service.impl;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.superquan.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @program: cloud2022
 * @description:
 * @author: superquan
 * @create: 2022-06-01 09:38
 **/
@Service
@Slf4j
public class PaymentServiceImpl implements PaymentService {
    @Override
    public String paymentInfo_OK(Integer id) {
        return "线程池："+Thread.currentThread().getName()+" paymentInfo_OK,id："+id+"\t"+"哦多克";
    }

//    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler",commandProperties = {
//            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="5000")
//    })
    @Override
    public String paymentInfo_TimeOut(Integer id) {
        int timeNumber=1;//超时
        int age= 10/0;//运行异常
//        try{
//            //暂停休眠3秒钟
////            TimeUnit.SECONDS.sleep(timeNumber);
//        }catch (InterruptedException e){
//            e.printStackTrace();
//        }
        return "线程池："+Thread.currentThread().getName()+" ,id："+id+"\t"+"哦多克"+",耗时（秒）："+timeNumber;
    }

    @Override
    public String paymentInfo_TimeOutHandler(Integer id) {
        log.info("****进入降级兜底方法，id："+id);
        return "线程池："+Thread.currentThread().getName()+" 8001系统繁忙或者运行报错，请稍后重试,id："+id+"\t"+"%>_<%";
    }
}
